package com.mic.security.web.controller;

import java.util.HashMap;
import java.util.Map;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.mic.security.event.AccessAttributeRefreshEvent;

@RestController("accessConfigController")
@RequestMapping("/sec")
public class AccessConfigController implements ApplicationEventPublisherAware {

	@RequestMapping("/refresh")
	public ResponseEntity<Map<String, Object>> refreshAccessConfigContext() {

		Map<String, Object> result = new HashMap<String, Object>();
		

		AccessAttributeRefreshEvent event = new AccessAttributeRefreshEvent(this);
		publisher.publishEvent(event);
		result.put("refresh", "权限更新成功");

		return new ResponseEntity<Map<String, Object>>(result, HttpStatus.OK);
	}

	private ApplicationEventPublisher publisher;

	@Override
	public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
		this.publisher = publisher;
	}

}
